local yilifuren = fk.CreateSkill {
  name = "lingling__yilifuren",
  dynamic_desc = function (self, player, lang)
    if player:usedSkillTimes("lingling__youjiaowulei", Player.HistoryGame) == 0 then
        return "当你对其他角色使用【杀】时，你可以与其拼点，若你赢则此【杀】无法抵消。当其他角色对你使用【杀】时，你可以与其拼点，若你赢则此【杀】无效。"
    else
        return "当你对其他角色使用【杀】时，你可以与其拼点，若你赢则此【杀】无法抵消。"
    end
  end,
}

Fk:loadTranslationTable{
  ["lingling__yilifuren"] = "以理服人",
  [":lingling__yilifuren"] = "当你对其他角色使用【杀】时，你可以与其拼点，若你赢则此【杀】无法抵消。当其他角色对你使用【杀】时，你可以与其拼点，若你赢则此【杀】无效。",

  ["#lingling__yilifuren1-invoke"] = "以理服人：你可以与 %dest 点，若赢，其不能响应此%arg",
  ["#lingling__yilifuren2-invoke"] = "以理服人：你可以与 %dest 拼点，若赢，此%arg对你无效",
}

yilifuren:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yilifuren.name) and data.card.trueName == "slash" and
      not data.to.dead and player:canPindian(data.to)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = yilifuren.name,
      prompt = "#lingling__yilifuren1-invoke::"..data.to.id..":"..data.card:toLogString(),
    }) then
      event:setCostData(self, {tos = {data.to}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local pindian = player:pindian({data.to}, yilifuren.name)
    if pindian.results[data.to].winner == player then
      data.use.disresponsiveList = data.use.disresponsiveList or {}
      table.insertIfNeed(data.use.disresponsiveList, data.to)
    end
  end,
})

yilifuren:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yilifuren.name) and data.card.trueName == "slash" and
      not data.from.dead and player:canPindian(data.from) and player:usedSkillTimes("lingling__youjiaowulei", Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = yilifuren.name,
      prompt = "#lingling__yilifuren2-invoke::"..data.from.id..":"..data.card:toLogString(),
    }) then
      event:setCostData(self, {tos = {data.from}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local pindian = player:pindian({data.from}, yilifuren.name)
    if pindian.results[data.from].winner == player then
      data.use.nullifiedTargets = data.use.nullifiedTargets or {}
      table.insertIfNeed(data.use.nullifiedTargets, player)
    end
  end,
})

return yilifuren